package com.eastfair.es.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@Document(indexName = "point_log_#{ T(com.eastfair.core.context.ContextUtil).getEsIndexSuffix() }", type = "_doc")
//指定映射es中的索引
@Mapping(mappingPath = "productIndex.json") // 解决IK分词不能使用问题
public class PointLog implements Serializable {
    @Id
    @Field(index = true, normalizer = "lowercase" , store = true, type = FieldType.Keyword)
    @ApiModelProperty(value = "主键id")
    private String id;

    @Field(index = false, normalizer = "lowercase" , store = true, type = FieldType.Keyword)
    @ApiModelProperty(value = "模块名称")
    private String applicaiontName;


    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Keyword)
    @ApiModelProperty(value = "埋点类型名称")
    private String pointName;

    @Field(index = false, normalizer = "lowercase" ,store = false, type = FieldType.Keyword)
    @ApiModelProperty(value = "端口")
    private Integer port;

    @Field(index = true, normalizer = "lowercase" ,store = false, type = FieldType.Keyword)
    @ApiModelProperty(value = "链路id")
    private String tarce;

    @Field(index = true, normalizer = "lowercase" ,store = false, type = FieldType.Keyword)
    @ApiModelProperty(value = "用户id")
    private Long userId;

    @Field(index = true, normalizer = "lowercase" ,store = false, type = FieldType.Keyword)
    @ApiModelProperty(value = "用户名")
    private String userName;

    @Field(index = true, normalizer = "lowercase" ,store = false, type = FieldType.Keyword)
    @ApiModelProperty(value = "ip地址")
    private String ip;

    //    @Field(index = false, store = true, type = FieldType.Date, format = DateFormat.basic_date_time)
    //date_time_no_millis
//    @Field( type = FieldType.Date,format = DateFormat.custom,
//            pattern = "yyyy-MM-dd HH:mm:ss")//不行没有格式
    @Field(index = false, store = true, type = FieldType.Date, format = DateFormat.date_time,pattern = "yyyy-MM-ddTHH:mm:ss.SSSZ")
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern ="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建时间")
    //时区问题，需要按中国时间 timezone
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;


    @Field(index = true, normalizer = "lowercase" ,store = false, type = FieldType.Text, analyzer = "ik_smart")
    @ApiModelProperty(value = "数据详情")
    private String msg;

    @Field(index = true, normalizer = "lowercase" ,store = true, type = FieldType.Keyword)
    //Text可以分词 ik_smart=粗粒度分词 ik_max_word 为细粒度分词
    @ApiModelProperty(value = "代码行数")
    private String codeNumber;
}
